<template>
	<view class="settings">
		<view class="content">
			<uv-cell-group>
				<uv-cell
					title="绑定手机号"
					clickable
					is-link
					:value="userStore.accountInfo.isMobileBound ? '已绑定' : '未绑定'"
					@click="toBindMobile"
				></uv-cell>
				<uv-cell title="设置提现密码" clickable is-link @click="handleToSetWithdrawalPasword"></uv-cell>
				<uv-cell title="隐私政策" clickable is-link @click="handleToPrivacy"></uv-cell>
				<uv-cell title="用户服务协议" clickable is-link @click="handleToAgreement"></uv-cell>
			</uv-cell-group>
			<!-- #ifdef APP-PLUS -->
			<view class="version">版本号：{{ version }}</view>
			<!-- #endif -->
			<view class="button">
				<uv-button @click="handleLogout" type="primary">退出登录</uv-button>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { useUserStore } from "../../store/user";
import config from "@/config.js";

const userStore = useUserStore();

const version = ref({});

const toBindMobile = () => {
	uni.navigateTo({
		url: "/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile"
	});
};

const handleLogout = async () => {
	uni.reLaunch({
		url: "/uni_modules/uni-id-pages/pages/login/login-withpwd"
	});
	await userStore.fetchLogout();
};

const handleToSetWithdrawalPasword = () => {
	uni.navigateTo({
		url: "/pages/set-withdrawal-password/set-withdrawal-password"
	});
};

function handleToPrivacy() {
	uni.navigateTo({
		url: `/pages/webview/webview?src=${config.privacyUrl}`
	});
}

function handleToAgreement() {
	uni.navigateTo({
		url: `/pages/webview/webview?src=${config.agreementUrl}`
	});
}

onShow(() => {
	const systemInfo = uni.getSystemInfoSync();
	console.log(systemInfo);
	version.value = systemInfo.version;
});
</script>

<style lang="scss" scoped>
.settings {
	height: 100%;
	display: flex;
	flex-direction: column;

	.content {
		flex: 1;

		.version {
			padding: 20px;
			text-align: center;
			background-color: #eeeeee;
			color: #696969;
		}

		.button {
			padding: 20px;
		}
	}
}
</style>
